package com.jeffse.light.stream.core.data.descriptor.stateDescriptor;

import com.jeffse.light.stream.core.data.context.KeyedContext;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 数据状态描述符
 * @param <T>
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class StateDescriptor <T> implements Serializable {
    protected String nameSpace;
    protected String stateName;
    protected String type;
    protected KeyedContext keyedContext;

    public StateDescriptor(String name, String type, T obj){
        // TODO 可以自定义键，方便后面的恢复操作，可以不指定，不指定当做默认规则处理，删除后无法恢复
        nameSpace = obj.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(obj));
        stateName = name;
        this.type = type;
        keyedContext = (KeyedContext) obj;
    }

    public String getStateKey(){
        return stateName + "_" + keyedContext.getCurrentKey();
    }
}
